<?php

namespace App\Jobs;

use App\Http\Services\DomainManager;
use App\Http\Services\YaoUserCenter;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class PostYaoUserCenter implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $phone;
    protected $name;
    protected $program_name;
    protected $ip;
    protected $userKey;
    protected $email;
    protected $head_img_url;
    protected $sex;
    protected $age;
    protected $area;
    protected $home_address;
    protected $update_at;

    public function __construct(string $phone ,string $name = '',string $program_name = '',string $ip = '',string $email = '',string $head_img_url = '' ,int $age = 0,int $sex = 0,string $area = '',string $home_address = '',int $update_at = 0,string $userKey = '')
    {
        $this->phone        = $phone;
        $this->name         = $name;
        $this->program_name = $program_name;
        $this->ip           = $ip;
        $this->userKey      = $userKey;
        $this->email        = $email;
        $this->head_img_url = $head_img_url;
        $this->sex          = $sex;
        $this->age          = $age;
        $this->area         = $area;
        $this->home_address = $home_address;
        $this->update_at    = $update_at;

    }

    /**
     * @return bool
     */
    public function handle()
    {
        //流程：登录->得到key->待定
        $yaoUser = new YaoUserCenter();
        $userKey = $yaoUser->userWechatRegOrLoginInYaoSystem($this->phone,$this->name,$this->program_name,$this->ip);
        if (!$userKey){
            \Log::notice("false=>userWechatRegOrLoginInYaoSystemNOTICE:($this->phone,$this->name,$this->program_name,$this->ip)");
            return false;
        }

//        $array = $yaoUser->jwtHandler($userKey);
//        if (!$array){
//            \Log::notice("false=>jwtHandlerNOTICE:($userKey)");
//            return false;
//        }
//
//        $userInfo = $yaoUser->getUserInfoInYaoSystem($userKey);
//        if (!$userInfo){
//            \Log::notice("false=>getUserInfoInYaoSystem($userKey)");
//            return false;
//        }

    }
}
